<?php

namespace App\Http\Controllers;

use App\Models\HouseList;
use App\Models\WxUser;
use App\Tools\JsonTools;
use App\Tools\RedisTools;
use Illuminate\Http\Request;

class HouseDetailController extends Controller
{
    /**
     * @Notes:
     * @Author:Planc,
     * @Date: 2022/11/18,
     * @Time: 15:22,
     * 房源详情
     */
    public function payHouseDetail(Request $request){
        $detailId=$request->get('detail_id');
        $detailRedis = (RedisTools::getInstance())->connectRedis()->get('payHouseDetail'.$detailId);
        if($detailRedis){
            return JsonTools::JsonSuccess(json_decode($detailRedis,true),200,'ok');
        }else{
            $detailInfo=HouseList::with(['houseMolding','houseBroker'])->where('id',$detailId)->first()->toArray();
            (RedisTools::getInstance())->connectRedis()->set('payHouseDetail'.$detailId,json_encode($detailInfo,256),3600);
            return JsonTools::JsonSuccess($detailInfo,200,'ok');
        }
    }

    /**
     * @Notes:
     * @Author:Planc,
     * @Date: 2022/11/21,
     * @Time: 14:45,
     * 获取uid
     */
    public function userToken(Request $request){
        $uid=$request->id;
        $userInfo=WxUser::where('id',$uid)->first()->toArray();
        $data=[
            'uid'=>$userInfo['id'],
            'userImage'=>$userInfo['user_image']
        ];
        return JsonTools::JsonSuccess($data,200,'ok');
    }

}
